home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / ZIP_1_0.lha / src / ztypes.h < prev   
C/C++ Source or Header  |  1992-10-13  |  13KB  |  603 lines

  1. /*
  2.  * ztypes.h
  3.  *
  4.  * Any global stuff required by the C modules.
  5.  *
  6.  */
  7.  
  8. #include <assert.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <time.h>
  13. #include <ctype.h>
  14.  
  15. /* Configuration options */
  16.  
  17. #define RIGHT_MARGIN 0 /* # of characters in right margin */
  18. #define TOP_MARGIN 2   /* # of lines left on screen before [MORE] message */
  19.  
  20. /* Global defines */
  21.  
  22. #ifndef TRUE
  23. #define TRUE 1
  24. #endif
  25.  
  26. #ifndef FALSE
  27. #define FALSE 0
  28. #endif
  29.  
  30. #ifndef FILENAME_MAX
  31. #define FILENAME_MAX 255
  32. #endif
  33.  
  34. #ifndef EXIT_SUCCESS
  35. #define EXIT_SUCCESS 0
  36. #endif
  37.  
  38. #ifndef EXIT_FAILURE
  39. #define EXIT_FAILURE 1
  40. #endif
  41.  
  42. #ifndef SEEK_SET
  43. #define SEEK_SET 0
  44. #endif
  45.  
  46. #ifndef SEEK_END
  47. #define SEEK_END 2
  48. #endif
  49.  
  50. #ifdef unix
  51.  
  52. #define strchr(a, b) index (a, b)
  53. #define memmove(a, b, c) bcopy (b, a, c)
  54.  
  55. #define const
  56.  
  57. #endif /* unix */
  58.  
  59. /* Z types */
  60.  
  61. typedef unsigned char zbyte_t;  /* unsigned 1 byte quantity */
  62. typedef unsigned short zword_t; /* unsigned 2 byte quantity */
  63.  
  64. /* Data file header format */
  65.  
  66. typedef struct zheader {
  67.     zbyte_t type;
  68.     zbyte_t config;
  69.     zword_t version;
  70.     zword_t data_size;
  71.     zword_t start_pc;
  72.     zword_t words_offset;
  73.     zword_t objects_offset;
  74.     zword_t globals_offset;
  75.     zword_t restart_size;
  76.     zword_t flags;
  77.     zbyte_t release_data[6];
  78.     zword_t synonyms_offset;
  79.     zword_t file_size;
  80.     zword_t checksum;
  81.     zbyte_t interpreter;
  82.     zbyte_t interpreter_version;
  83.     zbyte_t screen_rows;
  84.     zbyte_t screen_columns;
  85.     zword_t filler[15];
  86. } zheader_t;
  87.  
  88. #define H_TYPE 0
  89. #define H_CONFIG 1
  90.  
  91. #define CONFIG_BYTE_SWAPPED 0x01 /* Game data is byte swapped */
  92. #define CONFIG_TIME         0x02 /* Status line displays time */
  93. #define CONFIG_TANDY        0x08 /* Tandy licensed game         - V3 games */
  94. #define CONFIG_UNDERSCORE   0x08 /* Screen supports underscores - V4 games */
  95. #define CONFIG_NOSTATUSLINE 0x10 /* Interpreter cannot support a status line */
  96. #define CONFIG_WINDOWS      0x20 /* Interpreter supports windows */
  97.  
  98. #define H_VERSION 2
  99. #define H_DATA_SIZE 4
  100. #define H_START_PC 6
  101. #define H_WORDS_OFFSET 8
  102. #define H_OBJECTS_OFFSET 10
  103. #define H_GLOBALS_OFFSET 12
  104. #define H_RESTART_SIZE 14
  105. #define H_FLAGS 16
  106.  
  107. #define SCRIPTING_FLAG 0x01
  108. #define FIXED_FONT_FLAG 0x02
  109. #define SAVE_RESTORE_OK_FLAG 0x04
  110. #define SOUND_FLAG 0x10
  111. #define COLOUR_FLAG 0x40
  112.  
  113. #define H_RELEASE_DATE 18
  114. #define H_SYNONYMS_OFFSET 24
  115. #define H_FILE_SIZE 26
  116. #define H_CHECKSUM 28
  117. #define H_INTERPRETER 30
  118. #define H_INTERPRETER_VERSION 31
  119. #define H_SCREEN_ROWS 32
  120. #define H_SCREEN_COLUMNS 33
  121.  
  122. /* Version 3 object format */
  123.  
  124. #define V3 3
  125.  
  126. typedef struct zobjectv3 {
  127.     zword_t attributes[2];
  128.     zbyte_t parent;
  129.     zbyte_t next;
  130.     zbyte_t child;
  131.     zword_t property_offset;
  132. } zobjectv3_t;
  133.  
  134. #define O3_ATTRIBUTES 0
  135. #define O3_PARENT 4
  136. #define O3_NEXT 5
  137. #define O3_CHILD 6
  138. #define O3_PROPERTY_OFFSET 7
  139.  
  140. #define O3_SIZE 9
  141.  
  142. #define PARENT3(offset) (offset + O3_PARENT)
  143. #define NEXT3(offset) (offset + O3_NEXT)
  144. #define CHILD3(offset) (offset + O3_CHILD)
  145.  
  146. #define P3_MAX_PROPERTIES 0x20
  147.  
  148. /* Version 4 object format */
  149.  
  150. #define V4 4
  151.  
  152. typedef struct zobjectv4 {
  153.     zword_t attributes[3];
  154.     zword_t parent;
  155.     zword_t next;
  156.     zword_t child;
  157.     zword_t property_offset;
  158. } zobjectv4_t;
  159.  
  160. #define O4_ATTRIBUTES 0
  161. #define O4_PARENT 6
  162. #define O4_NEXT 8
  163. #define O4_CHILD 10
  164. #define O4_PROPERTY_OFFSET 12
  165.  
  166. #define O4_SIZE 14
  167.  
  168. #define PARENT4(offset) (offset + O4_PARENT)
  169. #define NEXT4(offset) (offset + O4_NEXT)
  170. #define CHILD4(offset) (offset + O4_CHILD)
  171.  
  172. #define P4_MAX_PROPERTIES 0x40
  173.  
  174. /* Local defines */
  175.  
  176. #define PAGE_SIZE 512
  177. #define PAGE_MASK 511
  178. #define PAGE_SHIFT 9
  179.  
  180. #define STACK_SIZE 512
  181.  
  182. #define ON 1
  183. #define OFF 0
  184. #define RESET -1
  185.  
  186. #define TEXT_WINDOW 0
  187. #define STATUS_WINDOW 1
  188.  
  189. #define NORMAL 0
  190. #define REVERSE 1
  191. #define BOLD 2
  192. #define BLINK 3
  193. #define UNDERSCORE 4
  194. #define NONE 5
  195.  
  196. #define GAME_RESTORE 0
  197. #define GAME_SAVE 1
  198. #define GAME_SCRIPT 2
  199.  
  200. /* Data access macros */
  201.  
  202. #define get_byte(offset) ((zbyte_t) datap[offset])
  203. #define get_word(offset) ((zword_t) (((zword_t) datap[offset] << 8) + (zword_t) datap[offset + 1]))
  204. #define set_byte(offset,value) datap[offset] = (zbyte_t) (value)
  205. #define set_word(offset,value) datap[offset] = (zbyte_t) ((zword_t) (value) >> 8), datap[offset + 1] = (zbyte_t) ((zword_t) (value) & 0xff)
  206.  
  207. /* External data */
  208.  
  209. extern zbyte_t h_type;
  210. extern zword_t h_version;
  211. extern zword_t h_data_size;
  212. extern zword_t h_start_pc;
  213. extern zword_t h_words_offset;
  214. extern zword_t h_objects_offset;
  215. extern zword_t h_globals_offset;
  216. extern zword_t h_restart_size;
  217. extern zword_t h_synonyms_offset;
  218. extern zword_t h_file_size;
  219. extern zword_t h_checksum;
  220.  
  221. extern int story_scaler;
  222. extern int story_shift;
  223. extern int property_mask;
  224. extern int property_size_mask;
  225.  
  226. extern zword_t stack[STACK_SIZE];
  227. extern zword_t sp;
  228. extern zword_t fp;
  229. extern unsigned long pc;
  230.  
  231. extern unsigned int data_size;
  232. extern zbyte_t *datap;
  233.  
  234. extern int entry_size;
  235. extern unsigned int dictionary_size;
  236. extern unsigned int dictionary_offset;
  237. extern char punctuation[];
  238.  
  239. extern int screen_rows;
  240. extern int screen_cols;
  241.  
  242. extern int window;
  243.  
  244. extern int format_mode;
  245. extern int output_enable;
  246. extern int scripting_disable;
  247.  
  248. extern int status_active;
  249. extern int status_size;
  250.  
  251. extern int lines_written;
  252. extern int char_count;
  253. extern int status_pos;
  254.  
  255. extern char *line;
  256. extern char *input;
  257. extern char *status_line;
  258.  
  259. extern char *restore_name;
  260.  
  261. /* Global routines */
  262.  
  263. /* control.c */
  264.  
  265. #ifdef __STDC__
  266. void call (int, zword_t *);
  267. void jump (zword_t);
  268. void pop (void);
  269. void pop_ret (void);
  270. void restart (void);
  271. void ret (zword_t);
  272. #else
  273. void call ();
  274. void jump ();
  275. void pop ();
  276. void pop_ret ();
  277. void restart ();
  278. void ret ();
  279. #endif
  280.  
  281. /* fileio.c */
  282.  
  283. #ifdef __STDC__
  284. int get_story_size (void);
  285. int restore (void);
  286. int save (void);
  287. int save_restore (const char *, int);
  288. void close_script (void);
  289. void close_story (void);
  290. void open_script (void);
  291. void open_story (const char *);
  292. void read_page (int, void *);
  293. void script_char (char);
  294. void script_line (const char *);
  295. void script_nl (void);
  296. void verify (void);
  297. #else
  298. int get_story_size ();
  299. int restore ();
  300. int save ();
  301. int save_restore ();
  302. void close_script ();
  303. void close_story ();
  304. void open_script ();
  305. void open_story ();
  306. void read_page ();
  307. void script_char ();
  308. void script_line ();
  309. void script_nl ();
  310. void verify ();
  311. #endif
  312.  
  313. /* input.c */
  314.  
  315. #ifdef __STDC__
  316. void read_character (int, zword_t *);
  317. void read_line (int, zword_t *);
  318. #else
  319. void read_character ();
  320. void read_line ();
  321. #endif
  322.  
  323. /* interpre.c */
  324.  
  325. #ifdef __STDC__
  326. void interpret (void);
  327. #else
  328. void interpret ();
  329. #endif
  330.  
  331. /* math.c */
  332.  
  333. #ifdef __STDC__
  334. void add (zword_t, zword_t);
  335. void and (zword_t, zword_t);
  336. void compare_je (int, zword_t *);
  337. void compare_jg (zword_t, zword_t);
  338. void compare_jl (zword_t, zword_t);
  339. void compare_zero (zword_t);
  340. void divide (zword_t, zword_t);
  341. void multiply (zword_t, zword_t);
  342. void not (zword_t);
  343. void or (zword_t, zword_t);
  344. void random (zword_t);
  345. void remainder (zword_t, zword_t);
  346. void subtract (zword_t, zword_t);
  347. void test (zword_t, zword_t);
  348. #else
  349. void add ();
  350. void and ();
  351. void compare_je ();
  352. void compare_jg ();
  353. void compare_jl ();
  354. void compare_zero ();
  355. void divide ();
  356. void multiply ();
  357. void not ();
  358. void or ();
  359. void random ();
  360. void remainder ();
  361. void subtract ();
  362. void test ();
  363. #endif
  364.  
  365. /* memory.c */
  366.  
  367. #ifdef __STDC__
  368. void load_cache (void);
  369. void unload_cache (void);
  370. zbyte_t read_code_byte (void);
  371. zbyte_t read_data_byte (unsigned long *);
  372. zword_t read_code_word (void);
  373. zword_t read_data_word (unsigned long *);
  374. #else
  375. void load_cache ();
  376. void unload_cache ();
  377. zbyte_t read_code_byte ();
  378. zbyte_t read_data_byte ();
  379. zword_t read_code_word ();
  380. zword_t read_data_word ();
  381. #endif
  382.  
  383. /* object.c */
  384.  
  385. #ifdef __STDC__
  386. void clear_attr (zword_t, zword_t);
  387. void compare_parent_object (zword_t, zword_t);
  388. void insert_object (zword_t, zword_t);
  389. void load_child_object (zword_t);
  390. void load_next_object (zword_t);
  391. void load_parent_object (zword_t);
  392. void remove_object (zword_t);
  393. void set_attr (zword_t, zword_t);
  394. void test_attr (zword_t, zword_t);
  395. zword_t get_object_address (zword_t);
  396. #else
  397. void clear_attr ();
  398. void compare_parent_object ();
  399. void insert_object ();
  400. void load_child_object ();
  401. void load_next_object ();
  402. void load_parent_object ();
  403. void remove_object ();
  404. void set_attr ();
  405. void test_attr ();
  406. zword_t get_object_address ();
  407. #endif
  408.  
  409. /* operand.c */
  410.  
  411. #ifdef __STDC__
  412. void conditional_jump (int);
  413. void store_operand (zword_t);
  414. void store_variable (int, zword_t);
  415. zword_t load_operand (int);
  416. zword_t load_variable (int);
  417. #else
  418. void conditional_jump ();
  419. void store_operand ();
  420. void store_variable ();
  421. zword_t load_operand ();
  422. zword_t load_variable ();
  423. #endif
  424.  
  425. /* osdepend.c */
  426.  
  427. #ifdef __STDC__
  428. void process_arguments (int, char *[]);
  429. void file_cleanup (const char *, int);
  430. void sound (int, zword_t *);
  431. int get_file_name (char *, char *, int);
  432. #else
  433. void process_arguments ();
  434. void file_cleanup ();
  435. void sound ();
  436. int get_file_name ();
  437. #endif
  438.  
  439. /* property.c */
  440.  
  441. #ifdef __STDC__
  442. void load_byte (zword_t, zword_t);
  443. void load_next_property (zword_t, zword_t);
  444. void load_property (zword_t, zword_t);
  445. void load_property_address (zword_t, zword_t);
  446. void load_property_length (zword_t);
  447. void load_word (zword_t, zword_t);
  448. void scan_word (zword_t, zword_t, zword_t);
  449. void store_byte (zword_t, zword_t, zword_t);
  450. void store_property (zword_t, zword_t, zword_t);
  451. void store_word (zword_t, zword_t, zword_t);
  452. #else
  453. void load_byte ();
  454. void load_next_property ();
  455. void load_property ();
  456. void load_property_address ();
  457. void load_property_length ();
  458. void load_word ();
  459. void scan_word ();
  460. void store_byte ();
  461. void store_property ();
  462. void store_word ();
  463. #endif
  464.  
  465. /* screen.c */
  466.  
  467. #ifdef __STDC__
  468. void blank_status_line (void);
  469. void display_status_line (void);
  470. void erase_line (zword_t);
  471. void erase_window (zword_t);
  472. void output_char (char);
  473. void output_nl (void);
  474. void output_string (const char *);
  475. void output_stringnl (const char *);
  476. void select_window (zword_t);
  477. void set_cursor_position (zword_t, zword_t);
  478. void set_status_size (zword_t);
  479. #else
  480. void blank_status_line ();
  481. void display_status_line ();
  482. void erase_line ();
  483. void erase_window ();
  484. void output_char ();
  485. void output_nl ();
  486. void output_string ();
  487. void output_stringnl ();
  488. void select_window ();
  489. void set_cursor_position ();
  490. void set_status_size ();
  491. void set_video_attribute ();
  492. #endif
  493.  
  494. /* screenio.c */
  495.  
  496. #ifdef __STDC__
  497. char input_character (void);
  498. void clear_line (void);
  499. void clear_screen (void);
  500. void clear_status_window (void);
  501. void clear_text_window (void);
  502. void create_status_window (void);
  503. void delete_status_window (void);
  504. void display_char (int);
  505. void fatal (const char *);
  506. int fit_line (const char *, int, int);
  507. void initialize_screen (void);
  508. void input_line (void);
  509. void move_cursor (int, int);
  510. int print_status (int, char *[]);
  511. void reset_screen (void);
  512. void restart_screen (void);
  513. void restore_cursor_position (void);
  514. void save_cursor_position (void);
  515. void scroll_line (void);
  516. void select_status_window (void);
  517. void select_text_window (void);
  518. void set_attribute (int);
  519. #else
  520. char input_character ();
  521. void clear_line ();
  522. void clear_screen ();
  523. void clear_status_window ();
  524. void clear_text_window ();
  525. void create_status_window ();
  526. void delete_status_window ();
  527. void display_char ();
  528. void fatal ();
  529. int fit_line ();
  530. void initialize_screen ();
  531. void input_line ();
  532. void move_cursor ();
  533. int print_status ();
  534. void reset_screen ();
  535. void restart_screen ();
  536. void restore_cursor_position ();
  537. void save_cursor_position ();
  538. void scroll_line ();
  539. void select_status_window ();
  540. void select_text_window ();
  541. void set_attribute ();
  542. #endif
  543.  
  544. /* text.c */
  545.  
  546. #ifdef __STDC__
  547. void decode_text (unsigned long *);
  548. void encode_text (int, const char *, short *);
  549. void flush_buffer (int);
  550. void new_line (void);
  551. void print_address (zword_t);
  552. void print_character (zword_t);
  553. void print_literal (void);
  554. void print_number (zword_t);
  555. void print_object (zword_t);
  556. void print_offset (zword_t);
  557. void print_time (int, int);
  558. void println_return (void);
  559. void set_format_mode (zword_t);
  560. void set_print_modes (zword_t, zword_t);
  561. void set_video_attribute (zword_t);
  562. void write_char (char);
  563. void write_string (const char *);
  564. #else
  565. void decode_text ();
  566. void encode_text ();
  567. void flush_buffer ();
  568. void new_line ();
  569. void print_address ();
  570. void print_character ();
  571. void print_literal ();
  572. void print_number ();
  573. void print_object ();
  574. void print_offset ();
  575. void print_time ();
  576. void println_return ();
  577. void set_format_mode ();
  578. void set_print_modes ();
  579. void set_video_attribute ();
  580. void write_char ();
  581. void write_string ();
  582. #endif
  583.  
  584. /* variable.c */
  585.  
  586. #ifdef __STDC__
  587. void decrement (zword_t);
  588. void decrement_check (zword_t, zword_t);
  589. void increment (zword_t);
  590. void increment_check (zword_t, zword_t);
  591. void load (zword_t);
  592. void pop_var (zword_t);
  593. void push_var (zword_t);
  594. #else
  595. void decrement ();
  596. void decrement_check ();
  597. void increment ();
  598. void increment_check ();
  599. void load ();
  600. void pop_var ();
  601. void push_var ();
  602. #endif
  603.